from gameset.phoenicia.base import *

from .coal import Charcoal


class Ore(RawMaterial):
    singular =_ ('Ore')
    plural   =_ ('Ore')


class Metal(ProcessedMaterial):
    singular   =_ ('Metal')
    plural     =_ ('Metal')
    ore        =_ (None)
    smelt_time =_ (0.1)
    
    @classmethod
    def production(cls):
        return Production(input    = cls.ores() + (Charcoal(cls.ore_quantity()),),
                          output   = cls(cls.ore_quantity()),
                          duration = cls.smelt_time)
    
    @classmethod
    def ores(cls):
        if isinstance(cls.ore, tuple):
            return cls.ore
        else:
            return (cls.ore,)
    
    @classmethod
    def ore_quantity(cls):
        return sum(ore.quantity for ore in cls.ores())


class MetalGood(ProcessedMaterial):
    singular   =_ ('Metal Good')
    plural     =_ ('Metal Good')
    metal      =_ (None)
    forge_time =_ (0.2)
    
    @classmethod
    def production(cls):
        return Production(input    = (cls.metal, Charcoal(cls.metal.quantity)),
                          output   = cls(cls.metal.quantity),
                          duration = cls.forge_time)


class Smelter(Workshop):
    name     =_ ('Smelter')
    color    =_ (Gray.dark)
    cost     =_ (350)
    staff    =_ (24)
    size     =_ (4)
    produces =_ (lambda self: tuple(metal.production() for metal in Metal.all_concrete_subtypes))


class Forge(Workshop):
    name     =_ ('Forge')
    color    =_ (Orange.dark + Black)
    cost     =_ (200)
    staff    =_ (15)
    produces =_ (lambda self: tuple(good.production() for good in MetalGood.all_concrete_subtypes))
